package com.lzy.factory;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author lyw
 * @Date 2023/2/18-下午3:47
 */
public class TimerTaskPoolFactory implements TimerTaskFactory {

  private final ScheduledExecutorService pool;

  public TimerTaskPoolFactory(ScheduledExecutorService pool) {
    this.pool = pool;
  }

  @Override
  public ScheduledFuture<?> createTimerTask(Runnable timerTask, final long delay, final long step, final TimeUnit unit) {
    ScheduledFuture<?> scheduledFuture = pool.scheduleAtFixedRate(timerTask, delay, step, unit);
    return scheduledFuture;
  }
}
